package com.five.admin.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.five.admin.dto.DeliveryOrderDTO;
import com.five.admin.dto.OrderQueryDto;
import com.five.admin.server.OrderItemService;
import com.five.admin.server.OrderService;
import com.five.admin.server.UserOrderService;
import com.five.admin.vo.OrderListVo;
import com.five.core.result.Result;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

@RestController
@RequestMapping("/order")
public class OderController {
    @Resource
    private OrderService orderService;

    @Resource
    private OrderItemService orderItemService;



    @RequestMapping(value = "/list", method = RequestMethod.POST)
    public Result list(@RequestBody OrderQueryDto queryDto) {
        Page<OrderListVo> list = orderService.list(queryDto);
        return Result.buildSuccess(list.getTotal(),list.getRecords());
    }

    @RequestMapping(value = "/queryOne/{id}", method = RequestMethod.GET)
    public Result queryOne(@PathVariable("id") Long id) {
        return Result.buildSuccess(orderItemService.getById(id));
    }

    @RequestMapping(value = "/sendOrder/{id}", method = RequestMethod.GET)
    public Result sendOrder(@PathVariable("id") Long id) {
        return orderService.sendOrder(id) ? Result.buildSuccess() : Result.buildFail("发货失败");
    }

    @GetMapping("/getOrderDetail/{id}")
    public Result getOrderDetail(@PathVariable("id") Long orderId) {
        return Result.buildSuccess(orderService.getOrderDetail(orderId));
    }

    @PostMapping("/delivery")
    public Result delivery(@RequestBody @Valid DeliveryOrderDTO deliveryOrderDTO){
        return orderService.delivery(deliveryOrderDTO)?Result.buildSuccess():Result.buildFail("发货失败");
    }

    @GetMapping("/complete/{orderId}")
    public Result complete(@PathVariable("orderId") Long orderId){
        return orderService.complete(orderId)?Result.buildSuccess():Result.buildFail("收货失败");
    }
}
